<?php
/**
 * 新闻列表
 */

namespace app\admin\model;


use app\common\model\Model;

class News extends Model
{

    const TABLE_NAME = 'news_list';
    const CACHE_EXPIRE_LEVEL = self::CACHE_EXPIRE_LEVEL_2;

    protected $name = self::TABLE_NAME;

    public static function getListQuery($keyword='',$publish_status=-1){

        $query =  self::commonQuery(self::TABLE_NAME);

        if($keyword){
            $query->where(['news_title'=>['like','%'.$keyword.'%']]);
        }
        if($publish_status>=0)
        {
            $query->where(['news_is_publish'=>$publish_status]);
        }

        return $query;

    }

    public static function getNewsInfo($news_id)
    {
       return  self::commonQuery(self::TABLE_NAME)->where(['news_id'=>$news_id])->find();
    }
    public static function handleInfo($news_info)
    {
        $news_info['news_time']=date('Y-m-d H:i:s',$news_info['news_time']);
        return $news_info;
    }

    public static function getNewsContent($news_id)
    {
        return self::commonQuery('news_content')->where(['content_news_id'=>$news_id])->value('content_text');
    }
    public static function updatePublishStatus($news_id,$publish_status)
    {
        return self::commonQuery(self::TABLE_NAME)
              ->where(['news_id'=>$news_id])
            ->setField('news_is_publish',$publish_status);
    }
    public static function deleteNews($news_id)
    {
        return self::commonQuery(self::TABLE_NAME)
                ->where(['news_id'=>$news_id])
                ->delete();
    }
}